#ifndef SNAKEWIDGET_H
#define SNAKEWIDGET_H

#include <QWidget>
#include "QPainter"
#include "QTimer"
#include "QKeyEvent"

namespace Ui {
class SnakeWidget;
}

class SnakeWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SnakeWidget(QWidget *parent = 0);
    ~SnakeWidget();
    void init(void);

protected:
    void paintEvent(QPaintEvent *);
    void keyPressEvent(QKeyEvent *event);

private:
    Ui::SnakeWidget *ui;
    QTimer *m_timer;
    int Snake[100][2];
    int foodPosition[2];
    int m_foodCount;
    int m_direction;
    int m_startSpeed;
    int m_score;
    int m_level;

private slots:
    void slotTimeOut();

    void on_UP_Button_clicked();

    void on_LEFT_Button_clicked();

    void on_RIGHT_Button_clicked();

    void on_DOWN_Button_clicked();

    void on_AddLevel_clicked();

    void on_ReduceLevel_clicked();

    void on_RebootButton_clicked();

private:
    void initBackground();
    void DrawSnakeHead();
    void Creatfood();
    void SnakeRun();
    void CheckEatfood();
    void SnakeHeadRun();
    bool SnakeOver();
    void initConnect();
    void GameOver();
    void initButton();
    void initGrades();
    void flashScore();
    void RebootSnake();
};

#endif // SNAKEWIDGET_H
